// =============  1. 原始类型（ES5 版）  =============
const a: null = null;
const b: undefined = undefined;
const c: boolean = true;
const d: number = 6;
const f: string = 'ts';

// =============  2. 包装对象（仅演示，不推荐）  =============
const h: String = new String('wrapper');
const i: Number = new Number(42);
const j: Boolean = new Boolean(false);

// =============  3. ES5 内置引用类型  =============
const k: object = {};
const l: Array<number> = [1, 2];
const m: Date = new Date();
const n: RegExp = /ab+c/;
const o: Error = new Error('oops');

// =============  4. 函数类型  =============
const t: () => void = () => {};
const u: (x: number) => string = x => x.toString();

// =============  5. 元组（TS 特有，ES5 兼容）  =============
const v: [string, number] = ['age', 18];

// =============  6. 枚举  =============
enum Color { Red, Green, Blue }
const w: Color = Color.Red;

// =============  7. Top / Bottom / Unknown  =============
const x: any = 7;
const y: unknown = 8;
function inf(): never { while (true) {} }

// =============  8. 字面量类型  =============
const z1: 'click' = 'click';
const z2: 404 = 404;

// =============  9. 联合 & 交叉  =============
type U = string | number;
type I = { a: string } & { b: number };

// =============  10. 索引与映射  =============
type Arr = number[];
type Dict = { [key: string]: boolean };
type RO = Readonly<{ x: number }>;
type Part = Partial<{ y: string; z: number }>;

// =============  11. 常用工具类型（TS 内置）  =============
type N = NonNullable<string | null>;
type R = ReturnType<typeof parseInt>;
type P = Parameters<typeof parseInt>;

// =============  12. 模板字符串类型  =============
type EventName<T extends string> = `${T}Changed`;
type E = EventName<'foo'>; // "fooChanged"

// =============  13. 类与接口  =============
class Point { x!: number; y!: number; }
interface IPoint { x: number; y: number; }
const pt: IPoint = new Point();

// =============  14. 泛型  =============
type Stack<T> = { push(item: T): void; pop(): T | undefined };
const numStack: Stack<number> = { push: () => {}, pop: () => 0 };

// =============  15. 可变元组  =============
type VT<T extends readonly unknown[]> = T;
type R1 = VT<[string, ...number[]]>;

// =============  16. 品牌类型  =============
declare const tag: unique symbol;
type USD = number & { [tag]: 'USD' };
const usd = 10 as USD;

// =============  17. 断言签名  =============
function assert(val: unknown): asserts val is string {
  if (typeof val !== 'string') throw 0;
}

// =============  18. const enum  =============
const enum Dir { Up = 1, Down = -1 }
const dir: Dir = Dir.Up;

// =============  19. 模板字面量 + 联合  =============
type Alignment = 'left' | 'right' | 'center';
type Margin = `margin-${Alignment}`;

// =============  20. 可变元组 + 标签  =============
type L = [first: string, ...rest: number[], last: boolean];

// =============  21. 静态索引签名  =============
type CSS = { [K in `--${string}`]: string | number };

// =============  22. 抽象构造签名  =============
abstract class Animal {}
type AnimalConstructor = abstract new (...args: any[]) => Animal;

// =============  23. satisfies（TS4.9+）  =============
const cfg = {
  port: 3000,
  host: '0.0.0.0'
} satisfies Record<string, string | number>;

// =============  24. in / out 修饰（TS5.0+）  =============
type Func<in T, out R> = (arg: T) => R;